package com.songlanyun.modules.ship.entity;

import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;

import java.io.Serializable;
import java.util.Date;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.songlanyun.common.drive.RootEntity;
import lombok.Data;
import org.apache.commons.lang.StringUtils;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;

/**
 * 订单包裹的物流信息
 * 
 * @author lubo
 * @email sunlightcs@gmail.com
 * @date 2020-11-19 13:49:33
 */
@Data
@TableName("yxt_sale_order_package_express")
public class OrderPackageExpress extends RootEntity<Long,OrderPackageExpress> implements Serializable {
	private static final long serialVersionUID = 1L;

	/**
	 * 
	 */
	@TableId
	private Long id;
	/**
	 * 包裹id
	 */
	@NotNull(message = "包裹id不能为空")
	private Long goodsPackageId;
	/**
	 * 物流公司代号
	 */
	@NotBlank(message = "必需设置物流公司代号")
	private String expressCode;
	/**
	 * 物流公司名称
	 */
	@NotBlank(message = "必需设置物流公司名称")
	private String expressName;
	/**
	 * 快递单号
	 */
	@NotBlank(message = "必需设置快递单号")
	private String logisticCode;
	/**
	 * 最后一次查询时间
	 */
	private Long lastQueryTime;
	/**
	 * 查询结果
	 */
	private String queryResult;


	@JsonIgnore
	public boolean isAbleSelect()
	{
		if(lastQueryTime==0)
		{
			return true;
		}

		if(StringUtils.isNotBlank(queryResult) && (lastQueryTime+12*60*60*1000)<System.currentTimeMillis())
		{
			return true;
		}


		if(StringUtils.isBlank(queryResult) && (lastQueryTime+2*60*60*1000)<System.currentTimeMillis())
		{
			return true;
		}
		return false;
	}


	@Override
	public Long getIdentity() {
		return getId();
	}
}
